package com.saihai.jiankang.ufJzg.controller;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.saihai.common.annotation.Log;
import com.saihai.common.core.controller.BaseController;
import com.saihai.common.core.domain.AjaxResult;
import com.saihai.common.enums.BusinessType;
import com.saihai.jiankang.ufJzg.domain.UfJzg;
import com.saihai.jiankang.ufJzg.service.IUfJzgService;
import com.saihai.common.utils.poi.ExcelUtil;
import com.saihai.common.core.page.TableDataInfo;

/**
 * 教职工Controller
 * 
 * @author ruoyi
 * @date 2024-08-05
 */
@RestController
@RequestMapping("/jiankang/ufJzg")
public class UfJzgController extends BaseController
{
    @Autowired
    private IUfJzgService ufJzgService;

    /**
     * 查询教职工列表
     */
    @PreAuthorize("@ss.hasPermi('jiankang:ufJzg:list')")
    @GetMapping("/list")
    public TableDataInfo list(UfJzg ufJzg)
    {
        startPage();
        List<UfJzg> list = ufJzgService.selectUfJzgList(ufJzg);
        return getDataTable(list);
    }

    @GetMapping("/aaa")
    public String AA() {
        String url = "http://172.0.10.161:9666/supplies/baseUse/list"; // 替换为实际的API地址
        String token = "EA0C140D35B3871230663C78B15ADAF5"; // 替换为实际的Token

        StringBuffer response = null;
        try {
            URL obj = new URL(url);
            HttpURLConnection con = (HttpURLConnection) obj.openConnection();

            // 添加Token到Header
            con.setRequestProperty("Authorization", "Bearer " + token);
            con.setRequestProperty("Content-Type","application/json");
            int responseCode = con.getResponseCode();
            System.out.println("Response Code : " + responseCode);

            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String inputLine;
            response = new StringBuffer();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        // 输出响应内容
        System.out.println("Response: " + response.toString());
        return response.toString();
    }

    /**
     * 导出教职工列表
     */
    @PreAuthorize("@ss.hasPermi('jiankang:ufJzg:export')")
    @Log(title = "教职工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UfJzg ufJzg)
    {
        List<UfJzg> list = ufJzgService.selectUfJzgList(ufJzg);
        ExcelUtil<UfJzg> util = new ExcelUtil<UfJzg>(UfJzg.class);
        util.exportExcel(response, list, "教职工数据");
    }

    /**
     * 获取教职工详细信息
     */
    @PreAuthorize("@ss.hasPermi('jiankang:ufJzg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ufJzgService.selectUfJzgById(id));
    }

    /**
     * 新增教职工
     */
    @PreAuthorize("@ss.hasPermi('jiankang:ufJzg:add')")
    @Log(title = "教职工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UfJzg ufJzg)
    {
        return toAjax(ufJzgService.insertUfJzg(ufJzg));
    }

    /**
     * 修改教职工
     */
    @PreAuthorize("@ss.hasPermi('jiankang:ufJzg:edit')")
    @Log(title = "教职工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UfJzg ufJzg)
    {
        return toAjax(ufJzgService.updateUfJzg(ufJzg));
    }

    /**
     * 删除教职工
     */
    @PreAuthorize("@ss.hasPermi('jiankang:ufJzg:remove')")
    @Log(title = "教职工", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ufJzgService.deleteUfJzgByIds(ids));
    }
}
